#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#define R 10
#define C 10
int main() {
    int r, c;
    int cnt = 0;
    while(cin >> r && r!= 0){
        ++cnt;
        if(cnt != 1) cout << endl;
        cout << "puzzle #" << cnt << ":" << endl;
        char a[R][C]; bool vis[R][C];
        cin >> c;
        for(int i=0; i<r; i++)
            for(int j=0; j<c; j++)
            {
                a[i][j] = 0;
                vis[i][j] = false;
            }

        for(int i=0; i<r; i++)
            for(int j=0; j<c; j++)
                cin >> a[i][j];

        int n=0;
        cout << "Across" << endl;
        for(int i=0; i<r; i++)
            for(int j=0; j<c; j++){
                if(a[i][j] != '*' &&(i==0 || j==0|| a[i-1][j]=='*' || a[i][j-1]=='*')){
                    ++n;
                    if(!vis[i][j]){
                        string s;
                        s.push_back(a[i][j]);
                        int tr = i, tc = j;
                        while(tc+1<c && a[tr][tc+1]!='*' && !vis[tr][tc+1]){
                            tc++;
                            s.push_back(a[tr][tc]);
                            vis[tr][tc] = true;
                        }
                        cout << setw(3) << n << "." << s << endl;
                    }
            }
        }

        n = 0;
        for(int i=0; i<r; i++)
            for(int j=0; j<c; j++)
            {
                vis[i][j] = false;
            }
        cout << "Down" << endl;
        for(int i=0; i<r; i++)
            for(int j=0; j<c; j++){
                if(a[i][j] != '*' &&(i==0 || j==0|| a[i-1][j]=='*' || a[i][j-1]=='*')){
                    ++n;
                    if(!vis[i][j]){
                        string s;
                        s.push_back(a[i][j]);
                        int tr = i, tc = j;
                        while(tr+1<r && a[tr+1][tc]!='*' && !vis[tr+1][tc]){
                            tr++;
                            s.push_back(a[tr][tc]);
                            vis[tr][tc] = true;
                        }
                        cout << setw(3) << n << "." << s << endl;
                    }
                }
            }
    }
    return 0;
}
/*
2 2
AT
*O
6 7
AIM*DEN
*ME*ONE
UPON*TO
SO*ERIN
*SA*OR*
IES*DEA
0

 */